<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-5-22
 * Time: 下午7:39
 */
class Girl extends CI_Controller {
    function __construct() {
        parent::__construct ();
        $this->load->database ();
    }


    /**
     * 文章管理
     */
    function girl_list()
    {
        $numPerPage = $this->input->post('numPerPage') >= 1 ? $this->input->post('numPerPage') : 20;
        $query = array();
        $query['query'] = $this->Mgirl->getGirlAll('',1,$numPerPage);
        //print_r($query);
        $query['numPerPage'] = $numPerPage;



        $this->load->view('girl_list',$query);
    }

    function add_girl()
    {
        $this->load->view('add_girl');
    }

    function loadGirl()
    {
        $title = $this->input->post('title');
        $status = !empty($_POST['status']) ?$_POST['status'] :1;

        $query = $this->Mgirl->getGirlAll($title,$status,20);
        //print_r($query['data']);
        $result = "";
        foreach ( $query['data'] as $row ) {
            $result .= "<tr>
					<td><input type='checkbox' value='" . $row['id'] . "' /></td>
							<td>".$row['id']."</td>
							<td>".$row['title']."</td>
							<td>".$row['city']."</td>
							<td>".$row['uid']."</td>
							<td>".$row['name']."</td>
							<td>".$row['voteCount']."</td>
							<td style='color:red;'>".($row['is_hot'] == 1 ?'是' : '否')."</td>
							<td style='color:red;'>".($row['status'] == 1 ?'显示' : '隐藏')."</td>
							<td>
			<a href='javascript:void(0)' style='color:blue' onclick='modifyGirl(" . $row['id'] . ")'>编辑</a>
			&nbsp;&nbsp;&nbsp;&nbsp;
					<a href='javascript:void(0)' style='color:blue' onclick='delSelectMultiGirl(" . $row['id'] . ")'>删除</a></td>
							";
            $result .= "</tr>";
        }


        echo $result;

    }

    function addGirl()
    {
        $title      = $this->input->post('title');
        $city       = $this->input->post('city');
        $name       = $this->input->post('name');
        $voteCount  = $this->input->post('voteCount');
        $id         = (int)$this->input->post('id');
        $uid        = $this->input->post('uid');
        $status     = (int)$this->input->post('status');
        $is_hot     = (int)$this->input->post('is_hot');


        if(empty($id)){
            $this->Mgirl->addGirl($title,$city,$name,$uid,$voteCount,$status,$is_hot);
        }else{
            $this->Mgirl->editGirl($id,$title,$city,$name,$uid,$voteCount,$is_hot,$status);
        }
        $data = array();
        $data['ReturnCode'] = 1;
        echo json_encode($data);
    }

    function delGirl()
    {
        $ids = trim($this->input->post('ids'),',');

        $this->Mgirl->deleteGirl($ids);
        $arr ["ReturnCode"] = 1;
        echo json_encode ( $arr );
    }

    function loadNewGirl()
    {
        $id = $this->input->post('id');
        if(!empty($id)){
            $data = $this->Mgirl->getGirlById($id);
        }

        echo json_encode($data);

    }

}